﻿@{
    Layout = null;
}

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>存货Bom数据管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/Common.js"></script>

</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="addWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1005;</i>保存
            </button>
        </li>
        
    </ul>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">

                            @* <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="bomCode" placeholder="Bom编码" autocomplete="off" class="layui-input" id="bomCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="relationCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="relationCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="relationCode" placeholder="存货名称" autocomplete="off" class="layui-input" id="relationCode">
                            </div>

                            <div class="layui-inline layui-show-xs-block">
                                <select id="ctype" class="tClass" name="ctype" autocomplete="off" lay-filter="parInfo">
                                    <option value="">数据类型</option>
                                </select>
                            </div> *@
                            <div class="layui-form-item">
                                <div class="layui-input-group" style="float:left;">
                                    <div class="layui-input-prefix">
                                        版号
                                    </div>
                                    <select id="byBarCode" name="byBarCode" lay-verify="required" style="width:120%"></select>
                                </div>
                            </div>


                            <input type="hidden" name="id" id="id">
                            <input type="hidden" name="bomCode" id="bomCode">
                            <input type="hidden" name="proCode" id="proCode">

                        </form>
                    </div>


                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    var databomCode = ""; var proCode = "";
    $(function () {
        databomCode = getUrlVariable("databomCode");
        proCode = getUrlVariable("proCode");
        $("input[ name='bomCode']").val(databomCode);
        $("input[ name='proCode']").val(proCode);

        CommonData(proCode, "byBarCode");

        loadData();
    })
    /**
    加载数据
    **/
    function loadData() {
        layui.use('table', function () {
            var condition = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            //给table赋值
            table.render({
                elem: '#list'
                , url: '../Basic/GetDataList?condition=' + condition + "&dataType=bombg" //数据接口
                , title: '数据列表'
                , page: true //开启分页
                , even: true
                , limits: [20, 50, 100]
                , limit: 20 //每页默认显示的数量
                , defaultToolbar: ['exports']
                , cols: [[ //表头
                    { type: 'checkbox' }
                    , { field: 'byBarCode', title: '样板条码编码', width: 110 }
                    , { field: 'byCode', title: '版号', width: 170 }
                    , { field: 'banzhou', title: '板周', width: 100 }
                    , { field: 'banchang', title: '板长', width: 200 }
                ]]
            });

            //监听行工具事件
            table.on('tool(list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'edit') {
                    InfoOpenPage('../Basic/CommonDataUpdate?dataId=' + data.id, data.cName + "-修改", "85%", "80%");
                }
                else if (layEvent == 'add') {

                }
                else if (layEvent == 'del') {
                    // layer.confirm('确认要删除该数据？', function (index) {
                    //     $.ajax({
                    //         url: "../Basic/DelCommonData",
                    //         type: "post",
                    //         data: { dataId: data.id },
                    //         success: function (data) {
                    //             if (data.result) {
                    //                 layer.msg("删除成功");
                    //             } else {
                    //                 layer.msg("删除失败");
                    //             }
                    //             loadData();
                    //         }
                    //     });
                    //     layer.close(index);
                    // });

                }
            });
            //监听单元格编辑
            table.on('edit(list)', function (obj) {
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
                $.ajax({
                    url: "../Basic/EditCommonNames",
                    data: { dataId: data.id, names: value },
                    type: "post",
                    success: function (data) {
                        if (!data.Result) {
                            layer.msg(data.Message);
                        }

                    }
                })

            });

        });
    }

    function addWin() {
        InfoOpenPage("../Basic/BomUpdate", "BOM数据更新", "85%", "90%");
    }
    //版号下拉列表
    function CommonData(type, kjClass) {
        $.ajax({
            url: "../Basic/GetByBarCode",
            data: { type: type },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                if (data.Result) {
                    var datas = data.Data;
                    for (var i = 0; i < datas.length; i++) {
                        $("." + kjClass).append("<option value=\"" + datas[i]["byBarCode"] + "\" >" + datas[i]["byBarCode"] + "</option>");
                    }
                }
            }
        });
    }
    
</script>
